package com.snakerflow.app.notice.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.snakerflow.app.notice.dao.NoticeDao;
import com.snakerflow.app.notice.entity.Notice;
import com.snakerflow.framework.orm.Page;
import com.snakerflow.framework.orm.PropertyFilter;
import com.snakerflow.framework.security.entity.Org;
import com.snakerflow.framework.security.entity.User;

@Component
public class NoticeManager {

	@Autowired
	private NoticeDao noticeDao;
	
	/**
	 * 保存、更新公告
	 * @param entity
	 */
	public void save(Notice entity){
		noticeDao.save(entity);
	}
	
	/**
	 * 根据主键ID删除对应的公告实体
	 * @param id
	 */
	public void delete(Long id) {
		noticeDao.delete(id);
	}
	
	/**
	 * 根据主键ID获取公告实体
	 * @param id
	 * @return
	 */
	public Notice get(Long id) {
		return noticeDao.get(id);
	}
	
	/**
	 * 根据标题名称，获取公告实体
	 * @param title
	 * @return
	 */
	public Notice findUserByTitle(String title) {
		return noticeDao.findUniqueBy("title", title);
	}
	
	/**
	 * 根据分页对象、过滤集合参数，分页查询公告列表
	 * @param page
	 * @param filters
	 * @return
	 */
	public Page<Notice> findPage(final Page<Notice> page, final List<PropertyFilter> filters) {
		return noticeDao.findPage(page, filters);
	}
	
	/**
	 * 根据分页对象、所属部门ID号，分页查询用户列表
	 * @param page
	 * @param orgId
	 * @return
	 */
	public Page<Notice> searchNotice(final Page<Notice> page, String title) {
		
		String hql = "from Notice notice where notice.title=?";
		return noticeDao.findPage(page, hql, title);
	}
}
